package com.atguigu.gmall.mq.receiver;

import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ：Shine
 * @description：
 * @date ：2021/3/4 19:55
 */
@Component
@Configuration
public class DeadLetterReceiver {

    @SneakyThrows
    @RabbitListener(queues = DeadLetterMqConfig.queue_dead_2)
    public void get(String meg, Message message, Channel channel) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        System.out.println("接收到的消息:\t" + meg);
        System.out.println("消息的接收时间:\t" + simpleDateFormat.format(new Date()));

        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
